<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'withdraw-form',
        'enableAjaxValidation' => false,
            ));
    ?>

    <?php
    $member = Member::model()->findByAttributes(array('member_id' => Yii::app()->user->id));
    $package = Package::model()->findByAttributes(array('package_id' => $member->package_id));
    
    $balance = $this->getCurrentUserBalance(Yii::app()->user->id);
    if ($balance < 10) {
        ?>
        <h3>Not enough money to withdraw</h3>
        <p class="note">minimum balance amount $10</p>
        <?php
    } else if ($package == NULL) {
        ?>
        <h3>You do not have any package. Please buy a package to withdraw</h3>        
        <?php
    }else {
        ?>
        <p class="note">Fields with <span class="required">*</span> and minimum balance amount $10 are required.</p>

        <?php echo $form->errorSummary($model); ?>

        
        <div class="row">
            <?php echo $form->labelEx($model, 'method'); ?>
            <?php //echo $form->textField($model, 'method', array('size' => 60, 'maxlength' => 255)); ?>
            <?php
            $selectedpp = $_GET['pp'];
            if($selectedpp == NULL){
                $selectedpp = "";
            }
            $pp = PaymentProcessor::model()->findByAttributes(array('payment_processors_id' => $selectedpp));
            
            $list = CHtml::listData(PaymentProcessor::model()->findAll("status=:status AND enable_for_withdraw=:enable_for_withdraw", array("status" => '1', "enable_for_withdraw" => '1')), 'payment_processors_id', 'name');
            echo $form->dropDownList($model, 'method', $list, array(
                'empty'    => 'Select Category',
                'onchange' => 'document.location.href = "/index.php/withdraw/create?pp=" + this.value',
                'options' => array($selectedpp=>array('selected'=>true)),
            ));
            ?>
            <?php echo $form->error($model, 'method'); ?>
            <?php if($pp->charge != null){ ?>
            <span style="color: red; font-weight: bold; margin-left: 10px">Charge Fee <?php echo $pp->charge; ?> %</span>
            <input type="hidden" id="charge_fee" value="<?php echo $pp->charge; ?>" />
            <?php } ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'amount'); ?>
            <?php echo $form->textField($model, 'amount', array('onkeyup'=>'calculate();')); ?>
            <?php echo $form->error($model, 'amount'); ?>
            <?php if($pp->charge != null){ ?>
            <span style="color: red; font-weight: bold; margin-left: 10px" id="charged_amount"></span>
            <?php } ?>
        </div>

        <!--    <div class="row">
        <?php //echo $form->labelEx($model, 'member_account_id'); ?>
        <?php //echo $form->textField($model, 'member_account_id', array('size' => 11, 'maxlength' => 11)); ?>
        <?php //echo $form->error($model, 'member_account_id');  ?>
            </div>-->

        <div class="row buttons">
            <?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save'); ?>
        </div>
        <?php
    }
    ?>
        <script>
            function calculate(){
                <?php if($pp->charge != null){ ?>
                    var amount = document.getElementById('Withdraw_amount').value;
                    var chargefee = document.getElementById('charge_fee').value;
                    var chargedamount = (amount*chargefee)/100;
                    document.getElementById("charged_amount").innerHTML="Charged Amount " + chargedamount + ". So, Your withdraw amount is " + (amount-chargedamount);
                <?php } ?>
            }
        </script>
    <?php $this->endWidget(); ?>

</div><!-- form -->